<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>车辆管理</title>

		<link rel="stylesheet" type="text/css" href="../bootstarp-3.3.7/css/bootstrap.min.css"/>
<script src="../assets/js/jquery-2.0.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" type="text/css" href="../bootstarp-table-1.11.1/bootstrap-table.min.css"/>
<script src="../bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>


 
		<script type="text/javascript">
			$(function() {

				$("#tab").bootstrapTable({

					url: "../truck/getAllTruck.lgg",
					pagination: true,
					pageSize: 5,
					queryParams: queryParams,
					columns: [{
						field: 'license',
						title: '车牌号',
						align: 'center'
					}, {
						field: 'trucktype',
						title: '车辆类型',
						align: 'center'
					}, {
						field: 'carry_capcty',
						title: '载重量',
						align: 'center'
					}, {
						field: 'truckage',
						title: '车龄',
						align: 'center'
					}, {
						field: 'truckstatus',
						title: '车辆状态',
						align: 'center'
					}, {
						title: '更新',
						align: 'center',
						formatter: function(value, row, index) {
							return '<button class="btn btn-info glyphicon glyphicon-edit" data-toggle="modal" data-target="#myModal2" onclick="gx(' + row.truck_id + ')"></button>'
						}
					}, {
						title: '删除',
						align: 'center',
						formatter: function(value, row, index) {
							return '<button class="btn-danger btn glyphicon glyphicon-trash" onclick="del(' + row.truck_id + ')"></button>'
						}
					}]

				})
                
                //添加
				$("#btn").click(function() {

					if($("#license").val().trim().length == 0 || $("#trucktype").val().trim().length == 0 ||
						$("#carry_capcty").val().trim().length == 0 || $("#truckage").val().trim().length == 0 ||
						$("#truckstatus").val().trim().length == 0 || $("#owner_type_id").val().trim().length == 0 ||
						$("#trucklocation").val().trim().length == 0
					) {
						alert("请输入添加内容!")
					} else {

						$.ajax({
							type: "post",
							url: "../truck/getTruckLicense.lgg",
							data: "license=" + $("#license").val(),
							success: function(data) {
								if(data == 1) {
									alert("车牌号存在!")
								} else {
									$.ajax({
										type: "post",
										url: "../truck/addTruck.sw",
										data: $("#f1").serialize(),
										success: function(data) {
											$("#myModal").modal("hide");
											$("#tab").bootstrapTable("refresh");
										}

									});
								}
							}

						});

					}

				})
                
                //修改
				$("#btn3").click(function() {
					if($("#license2").val().trim().length == 0 || $("#trucktype2").val().trim().length == 0 ||
						$("#carry_capcty2").val().trim().length == 0 || $("#truckage2").val().trim().length == 0 ||
						$("#truckstatus2").val().trim().length == 0
					) {
						alert("请输入修改内容!")
					} else {
						$.ajax({
							type: "post",
							url: "../truck/updateTruck.lgg",
							data: $("#f2").serialize(),
							success: function(data) {
								$("#myModal2").modal("hide");
								$("#tab").bootstrapTable("refresh");

							}

						});

					}

				})
                
                //模糊查询
				$("#select").click(function() {

					$("#tab").bootstrapTable("refresh");
				})
                
                //查询车辆拥有者
				$.getJSON("../truck/getAllOwnerTypeDim.lgg", function(data) {
					for(var i = 0; i < data.length; i++) {
						$("#owner_type_id").append("<option value='" + data[i].owner_type_id + "'>" + data[i].name + "</option>");
					}
				})

			})
            
            //查询单个
			function gx(truck_id) {
				//				alert(truck_id)
				$.ajax({
					type: "post",
					url: "../truck/getTruck.lgg",
					dataType: "JSON",
					data: "truck_id=" + truck_id,
					success: function(data) {
						//						alert(data.license+","+data.trucktype+","+data.carry_capcty+","+data.truckage+","+data.truckstatus);
						$("#license2").val(data.license);
						$("#trucktype2").val(data.trucktype);
						$("#carry_capcty2").val(data.carry_capcty);
						$("#truckage2").val(data.truckage);
						$("#truckstatus2").val(data.truckstatus);
						$("#truck_id").val(data.truck_id);

					}
				});
			}
            
            
            //删除
			function del(truck_id) {
				//				alert(1)
				$.ajax({
					type: "post",
					url: "../truck/deleteTruck.lgg",
					//					dataType: "JSON",
					data: "truck_id=" + truck_id,
					success: function(data) {
						$("#tab").bootstrapTable("refresh");
					}
				});

			}

            //模糊查询
			function queryParams() {

				return {

					'license': $("#license3").val(),
					'trucktype': $("#trucktype3").val()

				}

			}
		</script>
	</head>

	<body>
	<div align="center">
		<form class="form-inline">
			<div class="form-group">
					<label for="exampleInputEmail2">查询：</label>
		<input type="text" class="form-control" id="license3" name="license" value="" placeholder="车牌号" />
		
						<input type="text" class="form-control" id="trucktype3" name="trucktype" value="" placeholder="车辆类型" />
		
		<button type="button" class="btn btn-default btn-md glyphicon  glyphicon glyphicon-search" id="select"></button>

			<button type="button" class="btn btn-primary btn-md glyphicon glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal">
		</button>
		
		</div>
		</form>
		
	</div>
	
	<br />

		<table id="tab">

		</table>

		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
						<h4 class="modal-title" id="myModalLabel">
					车辆添加
				</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="f1">
							<div class="form-group">
								<label for="license" class="col-sm-2 control-label">车牌</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="license" name="license">
								</div>
							</div>
							<div class="form-group">
								<label for="trucktype" class="col-sm-2 control-label">车型</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="trucktype" name="trucktype">
								</div>
							</div>
							<div class="form-group">
								<label for="carry_capcty" class="col-sm-2 control-label">载重</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="carry_capcty" name="carry_capcty">
								</div>
							</div>
							<div class="form-group">
								<label for="truckage" class="col-sm-2 control-label">车龄</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="truckage" name="truckage">
								</div>
							</div>
							<div class="form-group">
								<label for="truckage" class="col-sm-2 control-label">所有者</label>
								<div class="col-sm-10">
									<select id="owner_type_id" name="owner_type_id" class="form-control">
										<option value="0">--请选择--</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="truckage" class="col-sm-2 control-label">所在位置</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="trucklocation" name="trucklocation">
								</div>
							</div>
							<div class="form-group">
								<label for="truckstatus" class="col-sm-2 control-label">当前状态</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="truckstatus" name="truckstatus">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal">
				</button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" id="btn">
				
				</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal -->
		</div>

		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">车俩维护</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" id="f2">
							<input type="hidden" class="form-control" id="truck_id" name="truck_id">
							<div class="form-group">
								<label for="license" class="col-sm-2 control-label">车牌</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="license2" name="license">
								</div>
							</div>
							<div class="form-group">
								<label for="trucktype" class="col-sm-2 control-label">车型</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="trucktype2" name="trucktype">
								</div>
							</div>
							<div class="form-group">
								<label for="carry_capcty" class="col-sm-2 control-label">载重</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="carry_capcty2" name="carry_capcty">
								</div>
							</div>
							<div class="form-group">
								<label for="truckage" class="col-sm-2 control-label">车龄</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="truckage2" name="truckage">
								</div>
							</div>
							<div class="form-group">
								<label for="truckstatus" class="col-sm-2 control-label">当前状态</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="truckstatus2" name="truckstatus">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" id="btn3"></button>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>